<?php ob_start(); ?>
<?php
$scriptWindowMsg = "
    $(function() {
        $('a#close').click(function() {
            window.close();
        });
    });";
$this->Html->scriptBlock($scriptWindowMsg, array('inline' => false));
?>
<style>
    .title-tbl {
        background-color: #dedddd;
        font-size: 13px;
        font-weight: bold;
    }
    thead {
      background-color: #dedddd;
    }
    .tbl-broking td {
        border-bottom: 1px solid #333333;
        border-left: 1px solid;
        border-right: 1px solid #333333;
    }
    .td-payment-r {
        width: 100px;
    }
    td {
        text-align: center;
        vertical-align: middle;
        border-color: #333333;
        border-style: solid;
        border-width: 1px;
        height: 30px;
    }
    .tbl-broking tr {
        height: 30px;
        margin: 0;
        padding: 0;
    }
    .tbl-broking-commission {
        border-left: none;
        border-top: none;
        height: auto;
        margin: 0;
        padding: 0;
        table-layout: fixed;
        width: 100%;
    }
    table {
        border-collapse: collapse;
        border-spacing: 0;
    }
    .clearfix:after {
        clear: both;
        content: ".";
        display: block;
        font-size: 0;
        height: 0;
        visibility: hidden;
    }
    .clearfix:after {
        clear: both;
        content: ".";
        display: block;
        height: 0;
        visibility: hidden;
    }
    .wrapper-table {
        height: auto;
        margin: 13px 0 0;
        padding: 0;
        width: 100%;
    }
    .clearfix {
        display: block;
    }
    .title-body-content {
        color: #A0002A;
        font-size: 17px;
        font-weight: bold;
        height: auto;
        margin: 0 0 0;
        padding: 0;
        text-align: center;
        width: 100%;
    }
    .wrapper-content-body {
        background-color: White;
        height: auto;
        margin: 0 0 60px;
        padding: 0 16px 0;
        width: 96.8%;
    }
    .wrapper-body {
        background-color: White;
        height: auto;
        margin: 0;
        padding: 10px 0 0;
        width: 100%;
    }
    .hightlight {
        background-color: yellow;
        font-weight: bold;
    }
    .line-content-tbl {
        font-size: 12px;
    }
    .td-payment {
        text-align: center;
        width: 200px;
    }
    .tbl-broking-r td {
        border-color: #333333;
        border-style: solid;
        border-width: 1px;
        height: 30px;
    }
    .td-ref-payment {
        text-align: center;
        width: 300px;
    }
    .td-paid {
        text-align: center;
        width: 200px;
    }
    .td-payer {
        text-align: center;
        width: 300px;
    }
</style>
<div class="title-body-content"><?php echo $title_for_layout; ?></div>
<div class="wrapper-table clearfix">
    <table class="tbl-broking-commission">
        <thead>
            <tr class="title-tbl" >
                <td class=""><?php echo $this->Paginator->sort('refid', 'Payment#'); ?></td>
                <td class=""><?php echo __('Reference#'); ?></td>
                <td class=""><?php echo __('Paid Amount'); ?></td>
                <td class=""><?php echo __('Payment date'); ?></td>
                <td class=""><?php echo __('Commission'); ?></td>
            </tr>
        </thead>
        <?php
        $total = array();
        //$totalUSD = 0;
        foreach ($paymentschedules AS $paymentschedule) {
            //if($paymentschedule['Paymentschedule']['exchange'] == '') {
                if(isset($total[$paymentschedule['Paymentschedule']['currency']])){
                    $total[$paymentschedule['Paymentschedule']['currency']] += $paymentschedule['Paymentschedule']['aih_amount'];
                } else {
                    $total[$paymentschedule['Paymentschedule']['currency']] = $paymentschedule['Paymentschedule']['aih_amount'];
                }
            //} else {
            //    $totalUSD += $paymentschedule['Paymentschedule']['aih_amount'];
            //}
            $checked = ($paymentschedule['Paymentschedule']['paid'] == '1') ? '&#10003;' : ' ';
            $actions = '<li>' . $this->Html->link(__('Edit'), array(
                        'controller' => 'paymentschedules',
                        'action' => 'edit',
                        $paymentschedule['Paymentschedule']['id'],
                    )) . '</li>';
            $actions .= ' ' . $this->Layout->adminRowActions($paymentschedule['Paymentschedule']['id']);
            $actions .= ' <li><div class="space3">|</div>' . $this->Html->link(__('Delete'), array(
                        'controller' => 'paymentschedules',
                        'action' => 'delete',
                        $paymentschedule['Paymentschedule']['id'],
                        'token' => $this->params['_Token']['key'],
                            ), null, __('Are you sure?')) . '</li>';

            $aih_date = '';
            if($paymentschedule['Paymentschedule']['aih_date'] != '0000-00-00') {
                $aih_date = date('m/d/Y', strtotime($paymentschedule['Paymentschedule']['aih_date']));
            }
            ?>
            <tr class="line-content-tbl">
                <td>
                    <a href="<?php echo Router::url('/admin/paymentschedules/payment_records/'.$paymentschedule['Paymentschedule']['id'], true); ?>" target="blank">
                        <?php echo $paymentschedule['Paymentschedule']['refid']; ?>
                    </a> 
                </td>
                <td><?php echo $paymentschedule['Paymentschedule']['refid_edit']; ?></td>
                <td style="text-align: right; background-color: yellow; padding-right: 3px;">
                    <?php echo $paymentschedule['Paymentschedule']['currency'] . ' ' . number_format($paymentschedule['Paymentschedule']['paid_amount'],2); ?>
                </td>
                <td><?php echo $aih_date; ?></td>
                <td style="text-align:right; padding-right:5px"><?php echo $paymentschedule['Paymentschedule']['currency'] . ' ' . number_format($paymentschedule['Paymentschedule']['aih_amount'],2); ?></td>
            </tr>
        <?php    
            }
        ?>
        <tr class="line-content-tbl" >
            <td colspan="2" style="text-align:right; padding-right:5px; vertical-align:middle; border: none;">
                <b>Total : </b>
            </td>
            <td style="text-align:right; padding-right:5px; vertical-align:middle; border: none;">
                
            </td>
            <td style="text-align:right; padding-right:5px; vertical-align:middle; border: none;"></td>
            <td style="text-align:right; padding-right:5px; border: none;">
                <b>
                <?php
                if($total!=null) {
                    foreach ($total as $key => $value){
                        echo $key . ' ' . number_format($value,2) . '<br />';
                    }
                }
                //if($totalUSD > 0) {
                //    echo '$ ' . $totalUSD;
                //}
                ?>
                </b>
            </td>
        </tr>
    </table>
</div>
<?php
    $HtmlCode= ob_get_contents();
    ob_end_flush();
    $file = '/home/johnso28/public_html/aihreinsurance.com/dompdf/aih/commission_report.html';
    file_put_contents($file, $HtmlCode);
?>

<div class="wrapper-button-form clearfix">
    <div class="button-form clearfix">
        <div class="button-aihre button-blue"><a href="JavaScript:void(0)" title="CLOSE" id="close"><?php echo __('CLOSE'); ?></a></div>
    </div>
</div>
<div class="wrapper-button-form clearfix">
    <div class="button-form clearfix">
        <a href="http://<?php echo $_SERVER['HTTP_HOST']; ?>/dompdf/dompdf.php?base_path=aih/&input_file=commission_report.html&paper=a4">Download PDF</a>
        &nbsp; | &nbsp;
        <?php echo $this->Html->link('Download Excel', '/phpexcel/commission.php?ids=' . $ids, null, array()); ?>
    </div>
</div>